import { FormControl,FormArray,FormGroup,FormBuilder,Validators} from '@angular/forms';
import { Observable } from 'rxjs';
/**
   * @description 电话号码的验证函数
   * @param control 
   */
export function mobileValidate(control:FormControl):any{
    let telephoneRegex = /^1(3|4|5|7|8)+\d{9}$/;
    let valid = telephoneRegex.test(control.value);
    console.log('电话号码的验证为'+valid);
    return valid?null:{mobile:true};
  }

  /**
   * @description 密码验证的处理函数
   * @param control 
   */
export function passwordValidate(group:FormGroup):any{
    var password = group.get('password').value;
    var repeatpassword = group.get('repeatpassword').value;
    let valid = (password === repeatpassword);
    // return valid?null:{password:true};
    var str = valid?null:{password:{descInfo:'密码个确认密码是不匹配的'}};
    return valid?true:{password:{descxxx:'密码个确认密码是不匹配的'}};
  }

  export function mobileAsyncValidator(control:FormControl){
    let telephoneRegex = /^1(3|4|5|7|8)+\d{9}$/;
    let valid = telephoneRegex.test(control.value);
    console.log('电话号码的验证为'+valid);
    return Observable.of(valid?null:{mobile:true}).delay(5000);
  }